package edu.gatech.cs2340.teamrocket.view;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import java.awt.Graphics;
import java.awt.Image;

import javax.swing.JButton;

import edu.gatech.cs2340.teamrocket.control.guicontrol.MainMenuControl;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * This is the main menu at the very beginning.
 * 
 * @author Wai Chip Ngai
 */
@SuppressWarnings("serial")
public class MainMenu extends JPanel {

	private MainMenuControl aControl;
	private final Image bg = new ImageIcon("img/menu_graphics/mainmenu.png").getImage();
	private final ImageIcon single = new ImageIcon("img/menu_graphics/singleplayer.png");
	private final ImageIcon singleclicked = new ImageIcon("img/menu_graphics/singleplayerclicked.png");
	private final ImageIcon multi = new ImageIcon("img/menu_graphics/multiplayer.png");
	private final ImageIcon multiclicked = new ImageIcon("img/menu_graphics/multiplayerclicked.png");
	private final ImageIcon load = new ImageIcon("img/menu_graphics/loadgame.png");
	private final ImageIcon loadclicked = new ImageIcon("img/menu_graphics/loadgameclicked.png");
	private final ImageIcon quit = new ImageIcon("img/menu_graphics/quitgame.png");
	private final ImageIcon quitclicked = new ImageIcon("img/menu_graphics/quitgameclicked.png");
	/**
	 * Create the application.
	 */
	public MainMenu(MainMenuControl aControl) {
		this.aControl = aControl;
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		setLayout(null);
		JButton btnNewGame = new JButton(single);
		btnNewGame.setRolloverIcon(singleclicked);
		btnNewGame.setBounds(30,429, 280, 72);
		btnNewGame.setOpaque(true);
		btnNewGame.setBorderPainted(false);

		btnNewGame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				aControl.startSingleGame();
			}
		});
		add(btnNewGame);


		JButton btnNewMultiplayerGame = new JButton(multi);
		btnNewMultiplayerGame.setRolloverIcon(multiclicked);
		btnNewMultiplayerGame.setBounds(358,429, 280, 72);
		btnNewMultiplayerGame.setOpaque(true);
		btnNewMultiplayerGame.setBorderPainted(false);
		btnNewMultiplayerGame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				aControl.startMultiPlayer();
			}
		});
		add(btnNewMultiplayerGame);

		JButton btnLoadGame = new JButton(load);
		btnLoadGame.setRolloverIcon(loadclicked);
		btnLoadGame.setBounds(716,429, 280, 72);
		btnLoadGame.setOpaque(true);
		btnLoadGame.setBorderPainted(false);
		btnLoadGame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				aControl.loadGame();
			}
		});
		add(btnLoadGame);

		JButton btnQuit = new JButton(quit);
		btnQuit.setRolloverIcon(quitclicked);
		btnQuit.setBounds(359,558, 280, 72);
		btnQuit.setOpaque(true);
		btnQuit.setBorderPainted(false);
		btnQuit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				aControl.quitGame();
			}
		});
		add(btnQuit);
	}

    public void paintComponent(Graphics g){
        g.drawImage(bg, 0, 0, null, null);
    }
}
